
import pymysql

# 连接到 MySQL 数据库
def read_mysql_database():
    # 配置数据库连接信息
    config = {
        'host': '192.168.10.10',
        'user': 'root',
        'password': '123456',
        'database': 'mysql',
        'port':'3307'
    }
    try:
        # 建立连接
        conn = pymysql.connect(**config)
        cursor = conn.cursor()
        # 执行 SQL 查询
        cursor.execute("SELECT * FROM user")
        # 获取查询结果
        results = cursor.fetchall()
        for row in results:
            print(row)
    except pymysql.MySQLError as e:
        print(f"MySQL 错误: {e}")
    finally:
        # 关闭连接
        conn.close()


# 调用函数
read_mysql_database()
